package com.zbkj.crmeb.user.controller;

import com.common.CommonPage;
import com.common.CommonResult;
import com.common.PageParamRequest;
import com.zbkj.crmeb.user.request.UserIntegralIncrementRecordRequest;
import com.zbkj.crmeb.user.request.UserIntegralIncrementRecordSearchRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;
import com.zbkj.crmeb.user.service.UserIntegralIncrementRecordService;
import com.zbkj.crmeb.user.model.UserIntegralIncrementRecord;


/**
 *  前端控制器
 */
@Slf4j
@RestController
@RequestMapping("api/admin/user-integral-increment-record")
@Api(tags = "") //配合swagger使用

public class UserIntegralIncrementRecordController {

    @Autowired
    private UserIntegralIncrementRecordService userIntegralIncrementRecordService;

    /**
     * 分页显示
     * @param request 搜索条件
     * @param pageParamRequest 分页参数
     * @author Mr.Zhang
     * @since 2021-07-19
     */
    @ApiOperation(value = "分页列表") //配合swagger使用
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public CommonResult<CommonPage<UserIntegralIncrementRecord>>  getList(@Validated UserIntegralIncrementRecordSearchRequest request, @Validated PageParamRequest pageParamRequest){
        CommonPage<UserIntegralIncrementRecord> userIntegralIncrementRecordCommonPage = CommonPage.restPage(userIntegralIncrementRecordService.getList(request, pageParamRequest));
        return CommonResult.success(userIntegralIncrementRecordCommonPage);
    }

    /**
     * 新增
     * @param userIntegralIncrementRecordRequest 新增参数
     * @author Mr.Zhang
     * @since 2021-07-19
     */
    @ApiOperation(value = "新增")
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public CommonResult<String> save(@Validated UserIntegralIncrementRecordRequest userIntegralIncrementRecordRequest){
        UserIntegralIncrementRecord userIntegralIncrementRecord = new UserIntegralIncrementRecord();
        BeanUtils.copyProperties(userIntegralIncrementRecordRequest, userIntegralIncrementRecord);

        if(userIntegralIncrementRecordService.save(userIntegralIncrementRecord)){
            return CommonResult.success();
        }else{
            return CommonResult.failed();
        }
    }

    /**
     * 删除
     * @param id Integer
     * @author Mr.Zhang
     * @since 2021-07-19
     */
    @ApiOperation(value = "删除")
    @RequestMapping(value = "/delete", method = RequestMethod.DELETE)
    public CommonResult<String> delete(@RequestParam(value = "id") Integer id){
        if(userIntegralIncrementRecordService.removeById(id)){
            return CommonResult.success();
        }else{
            return CommonResult.failed();
        }
    }

    /**
     * 修改
     * @param id integer id
     * @param userIntegralIncrementRecordRequest 修改参数
     * @author Mr.Zhang
     * @since 2021-07-19
     */
    @ApiOperation(value = "修改")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public CommonResult<String> update(@RequestParam Integer id, @Validated UserIntegralIncrementRecordRequest userIntegralIncrementRecordRequest){
        UserIntegralIncrementRecord userIntegralIncrementRecord = new UserIntegralIncrementRecord();
        BeanUtils.copyProperties(userIntegralIncrementRecordRequest, userIntegralIncrementRecord);
        userIntegralIncrementRecord.setId(id);

        if(userIntegralIncrementRecordService.updateById(userIntegralIncrementRecord)){
            return CommonResult.success();
        }else{
            return CommonResult.failed();
        }
    }

    /**
     * 查询信息
     * @param id Integer
     * @author Mr.Zhang
     * @since 2021-07-19
     */
    @ApiOperation(value = "详情")
    @RequestMapping(value = "/info", method = RequestMethod.GET)
    public CommonResult<UserIntegralIncrementRecord> info(@RequestParam(value = "id") Integer id){
        UserIntegralIncrementRecord userIntegralIncrementRecord = userIntegralIncrementRecordService.getById(id);
        return CommonResult.success(userIntegralIncrementRecord);
   }
}



